#include <rttr/type>
#include <rttr/instance>
#include <rttr/property>
#include <rttr/method>

#include <iostream>
#include <rttr/registration>

// 定义一个简单的类
class Person
{
public:
    Person(const std::string& name, int age) : name(name), age(age) {}

    void say_hello() const
    {
        std::cout << "Hello, my name is " << name << " and I am " << age << " years old." << std::endl;
    }

    std::string get_name() const { return name; }
    int get_age() const { return age; }

private:
    std::string name;
    int age;
};

// 使用RTTR宏注册类及其成员
RTTR_ENABLE(Person)

int main()
{
    // 创建一个Person实例
    Person person("Alice", 30);

    // 使用RTTR获取类型信息
    rttr::type type = rttr::type::get<Person>();
    if (type.is_valid())
    {
        std::cout << "Type name: " << type.get_name().to_string() << std::endl;

        // 获取并调用方法
        auto method = type.get_method("say_hello");
        if (method.is_valid())
        {
            method.invoke(person);
        }

        // 获取并访问属性
        auto name_property = type.get_property("name");
        if (name_property.is_valid())
        {
            std::string name = name_property.get_value(person).to_string();
            std::cout << "Name: " << name << std::endl;
        }

        auto age_property = type.get_property("age");
        if (age_property.is_valid())
        {
            int age = age_property.get_value(person).to_int();
            std::cout << "Age: " << age << std::endl;
        }
    }
    else
    {
        std::cerr << "Type is not registered with RTTR!" << std::endl;
    }

    return 0;
}